package com.yupi.referral.utils;

import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

//文件上传工具类
public class FileUploadUtils {

    public static final long FILE_MAX_SIZE = 1024 * 1024 * 50;

    //随机生成文件名
    public static String extractFileName(MultipartFile file){
        //获得原始文件名
        String filename = file.getOriginalFilename();
        //通过文件名获得文件后缀  1112121.jpg -->.jpg
        String extension =
                filename.substring(filename.lastIndexOf("."));
        String randomName =
                UUID.randomUUID().toString().replace("-", "");
        String name = randomName + extension;
        return name;
    }


}
